package com.liner;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class MethodDemo {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);


        a();  // 222 444 333 111
        System.out.println("111");


        say("张三", 12);
        say("李四", 56);
        say("小亮");
        say();
        System.out.println(say2());
        plus(54, 12);
        System.out.println(plus2(12, 14));

        System.out.println("-------------------");
        int num1 = 43, num2 = 21;
        plus(num1, num2);

        System.out.print("请输入想生成的数组长度：");
        int len = scanner.nextInt();
        System.out.print("请输入想生成的随机数范围：");
        int random = scanner.nextInt();
        System.out.println("您所生成的数组为:");
        int[] array = generateArray(len,random);
        System.out.println(Arrays.toString(array));

        int[] ints = generateArray();
        System.out.println(Arrays.toString(ints));
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i] + "\t");
        }
        for (int j : ints){
            System.out.print(j + " , ");
        }


        Arrays.sort(ints);
        System.out.println(Arrays.toString(ints));
        System.out.println("ints数组的长度是：" + ints.length);
        System.out.println("ints数组的最大值是：" + max(ints));
        System.out.println("ints数组的最小值是：" + min(ints));
    }


    private static void a(){
        System.out.println("222");
        b();
        System.out.println("333");
    }
    private static void b(){
        System.out.println("444");
    }


    private static int min(int[] a) {
        int min = a[0];
        for (int j : a) {
            if (min > j) {
                min = j;
            }
        }
        return min;

    }

    public static int[] generateArray(int len,int random1) {
        Random random = new Random();
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(random1 + 1);
        }
        return arr;
    }


    public static int[] generateArray() {
        Random random = new Random();
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100);
        }
        return arr;
    }

    public static int max(int[] a) {
        int max = a[0];
        for (int j : a) {
            if (max < j) {
                max = j;
            }
        }
        return max;
    }


    public static void say(String name, int age) {
        if (age > 50){
            System.out.println("大家好，我叫" + name + "年龄就不告诉你了");
            return;
        }
        System.out.println("大家好，我叫" + name + "今年" + age + "岁了");
    }

    public static void say(String name) {
        System.out.println("大家好，我叫" + name);
    }

    //无参无返回值
    public static void say() {
        System.out.println("————————有参无返回值————————");
        System.out.println("hello world");
    }

    //无参有返回值
    public static int say2() {
        System.out.println("————————无参有返回值————————");
        return 1;
    }

    //有参无返回值
    public static void plus(int num1, int num2) {
        System.out.println("————————有参无返回值————————");
        System.out.println(num1 + " + " + num2 + "=" + (num1 + num2));
    }

    //有参有返回值
    public static int plus2(int num1, int num2) {
        System.out.println("————————有参有返回值————————");
        return num1 + num2;
    }


}
